import java.util.HashSet;
import java.util.Set;

public class Solution873 {
    public int lenLongestFibSubseq(int[] arr) {
        Set<Integer> set=new HashSet<>();
        for (int i : arr) {
            set.add(i);
        }
        int max=0;
        for (int i=0;i<arr.length;i++){
            for (int j=i+1;j<arr.length;j++){
                int x=arr[i],y=arr[j],c=2;
                while (set.contains(x+y)){
                    c++;
                    int z=x+y;
                    x=y;
                    y=z;
                }
                max=Math.max(max,c);
            }
        }
        return max<3?0:max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution873().lenLongestFibSubseq(new int[]{1,2,3,4,5,6,7,8}));
    }
}
